package com.yan;


import com.yan.bean.DeptTest;
import com.yan.common.mq.dirct.RabbitMqSender;
import com.yan.common.mq.fandout.FanoutSender;
import com.yan.common.mq.topic.TopicSender;
import com.yan.common.mq.xml.Producer;
import com.yan.mapper.DeptTestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.access.method.P;

/**
 * Created by yanl_ on 2018/4/1.
 *
 * @ImportResource({"classpath*:spring.xml"}) 表示引用配置文件来配置RabbitMq队列,其他的我写在Bean中了
 * 本项目主要将xml配置项改为bean
 *
 */

@EnableScheduling
@SpringBootApplication
@ServletComponentScan
@ImportResource({"classpath*:spring.xml"})
public class MyBootApplication extends SpringBootServletInitializer {

    private static Logger logger = LoggerFactory.getLogger(MyBootApplication.class);

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(MyBootApplication.class);
    }


    public static void main(String[] args) {

//        logger.info("app start...");
//        SpringApplication.run(MyBootApplication.class);
//        logger.info("app success end...");

        ConfigurableApplicationContext appContext = SpringApplication.run(
                MyBootApplication.class, args);


        RabbitMqSender rabbitMqSend = appContext.getBean(RabbitMqSender.class);

        rabbitMqSend.send("=test====================");
        rabbitMqSend.sendtest3("test3333333333333");
        rabbitMqSend.sendMessage();


        FanoutSender fanoutSender = appContext.getBean(FanoutSender.class);

        fanoutSender.send();


        TopicSender topicSender = appContext.getBean(TopicSender.class);

        topicSender.send1();


        Producer producer = appContext.getBean(Producer.class);
        producer.test();

        System.out.println("===================================================================");


        DeptTestService deptsServce = appContext.getBean("deptTestService", DeptTestService.class);
        DeptTest dept = deptsServce.selectByPrimaryKey(20L);

        System.out.println(dept);
    }
}

